package com.example.demo_mvvm.http;

import retrofit2.Retrofit;

import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author yaotianxue
 * @description
 * @date 2025/1/9
 */
public class RetrofitManager {
    //单例模式：懒汉双重锁校验 节省资源
    private RetrofitManager(){}
    private static RetrofitManager sRetrofitManager;//区分成员变量m 静态变量s 局部变量
    public static RetrofitManager getInstance(){
        if(sRetrofitManager == null){
            synchronized (RetrofitManager.class){
                if(sRetrofitManager == null){
                    sRetrofitManager = new RetrofitManager();
                }
            }
        }
        return sRetrofitManager;
    }

    private Retrofit mRetrofit;
    public Retrofit getRetrofit() {
        if(mRetrofit == null){
            createRetrofit();
        }
        return mRetrofit;
    }
    //构建Retrofit对象
    private void createRetrofit() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl("http://10.161.9.80:7012")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

}
